﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TA.Bluetooth;
using System.IO;

namespace BTClientXP
{
    class BTClientXP
    {
        static void Main(string[] args)
        {
            // BT connection
            String mac = "001BDC0FE81D"; // MAC-Addresse von Roboter 21
            Console.WriteLine("Search for device " + mac + "...");
            // desired service
            Guid service = BluetoothServiceList.Robot21;
            try
            {
                // connect to desired service
                BluetoothClient bc = BluetoothDevice.Connect(mac, service);
                if (bc != null)
                {
                    Console.WriteLine("Outgoing connection " + bc.GetSocket().LocalEndPoint + ".");
                    // read ASCII text file
                    string filename = @"c:\temp\drv_cmd_04.txt";
                    StreamReader sr = new StreamReader(filename);
                    string lines = sr.ReadToEnd();                   
                    // print 
                    Console.WriteLine("Message read : ");
                    Console.WriteLine(lines);
                    sr.Close();
                    // write ASCII text file to server
                    StreamWriter sw = new StreamWriter(bc.GetStream());
                    sw.WriteLine(lines);
                    sw.Flush();
                    sw.Close();
                    
                    // close BT connection
                    bc.Close();
                }
                else
                {
                    Console.WriteLine("Target does not exist");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
    }
}
